package cn.edu.gzy.web.server.service;

import cn.edu.gzy.web.server.service.dto.MovieInfo;
import cn.edu.gzy.web.server.service.impl.MovieInfoServiceJdbcImpl;
import cn.edu.gzy.web.server.utils.Page;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


/**
 * @Author guzy
 * @Description
 * @Date 2022/4/24 20:06
 **/
@SpringBootTest
public class MovieServiceTestMain {

    @Autowired
    MovieInfoServiceJdbcImpl movieInfoService;

    @Test
    public void fu() {

        System.out.println("进⾏MovieInfoService的业务逻辑测试：");
        System.out.println("【⽤例1】分⻚获取全部影⽚信息,输⼊参数page:1,size:50");

        try {
            Page<MovieInfo> movieInfoPage = movieInfoService.getAllMovieInfo(1, 50);
            if (movieInfoPage != null) {
                System.out.printf("【⽤例1】得到结果->记录总数：%s,分⻚总数：%s,当前数组记录数： %s, 是否⾸⻚：%s\n ", movieInfoPage.getTotalCount(), movieInfoPage.getPageCount(), movieInfoPage.getContent().size(), movieInfoPage.getFirst());
            }
        } catch (Exception e) {
            System.out.println("【出错】分⻚获取全部影⽚信息:" + e.getMessage());
        }

        System.out.println("【⽤例1】执⾏完毕");
        System.out.println("-----------------------------------------------");
        System.out.println("【⽤例2】根据关键字查询影⽚列表,输⼊参数keywords:变形,page:0,size:2");
        try {
            Page<MovieInfo> movieInfoPage =
                    movieInfoService.getMoviesByKeywords("变形", 0, 2);
            if (movieInfoPage != null) {
                System.out.printf("【⽤例2】得到结果->记录总数：%s,分⻚总数：%s,当前数组记录数：%s,是否⾸⻚：%s\n", movieInfoPage.getTotalCount(), movieInfoPage.getPageCount(), movieInfoPage.getContent().size(), movieInfoPage.getFirst());

            }
        } catch (Exception e) {
            System.out.println("【出错】根据关键字查询影⽚列表:" + e.getMessage());
        }

        System.out.println("【⽤例2】执⾏完毕");
        System.out.println("-----------------------------------------------");
        System.out.println("【⽤例3】发布⼀部影⽚,输⼊参数name:测试影⽚（时间 戳）,length:101");

        Long movieId = 0l;
        try {
            MovieInfo publishMovie = new MovieInfo();
            publishMovie.setMovieName("测试影⽚" + System.currentTimeMillis());
            publishMovie.setMovieLength(101);
            publishMovie = movieInfoService.publishMovieInfo(publishMovie);
            movieId = publishMovie.getMovieId();
            System.out.printf("【⽤例3】保存成功,得到id%s\n", publishMovie.getMovieId());

        } catch (Exception e) {
            System.out.println("【出错】发布⼀部影⽚:" + e.getMessage());
        }

        System.out.println("【⽤例3】执⾏完毕");
        System.out.println("-----------------------------------------------");
        System.out.println("【⽤例4】查询指定影⽚,输⼊参数movieId:" + movieId);


        try {
            MovieInfo movieInfo = movieInfoService.getMovieById(movieId);
            System.out.printf("【⽤例4】查到结果->影⽚id：%s,影⽚名称：%s\n", movieInfo.getMovieId(), movieInfo.getMovieName());
        } catch (Exception e) {
            System.out.println("【出错】发布⼀部影⽚:" + e.getMessage());
        }
        System.out.println("【⽤例4】执⾏完毕");
        System.out.println("-----------------------------------------------");
        System.out.println("【⽤例5】更新指定影⽚,输⼊参数movieId:" + movieId + "name:修改后测试影⽚（时间戳）, length:105, 英⽂名称: movie ");


        try {
            MovieInfo movieInfo = movieInfoService.getMovieById(movieId);
            movieInfo.setMovieLength(105);
            movieInfo.setMovieName("修改后测试影⽚" + System.currentTimeMillis());
            movieInfo.setMovieEnglishName("movie");
            movieInfoService.modifyMovieInfo(movieInfo);
            movieInfo = movieInfoService.getMovieById(movieId);
            System.out.printf("【⽤例5】保存成功->影⽚id：%s,影⽚名称：%s,英⽂名称：%s\n", movieInfo.getMovieId(), movieInfo.getMovieName(), movieInfo.getMovieEnglishName());
        } catch (Exception e) {
            System.out.println("【出错】更新指定影⽚:" + e.getMessage());
        }
        System.out.println("【⽤例5】执⾏完毕");
        System.out.println("-----------------------------------------------");

        System.out.println("【⽤例6】删除指定影⽚,输⼊参数movieId:" + movieId);
        try {
            boolean flag = movieInfoService.deleteMovieInfo(movieId);
            System.out.printf("【⽤例6】删除结果：->%s\n", flag);
            if (flag) {
                MovieInfo movieInfo = movieInfoService.getMovieById(movieId);
                System.out.printf("【⽤例6】删除后⼆次查询结果：-> %s\n ", movieInfo.getMovieName());
            }
        } catch (Exception e) {
            System.out.println("【出错】删除指定影⽚:" + e.getMessage());
        }
        System.out.println("【⽤例6】执⾏完毕");
        System.out.println("-----------------------------------------------");
    }
}





